package com.wl.gateway.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.http.ZuulServlet;
import javax.servlet.http.HttpServletResponse;

/**
 * @author wangl
 * @desc
 * @date:2017/6/2616:02
 * @Copyright (c) 2017, DaChen All Rights Reserved.
 */
public class ErrorFilter extends ZuulFilter{

    @Override
    public String filterType() {
        return "error";
    }

    @Override
    public int filterOrder() {
        return 10;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() {
        RequestContext rtx = RequestContext.getCurrentContext();
        Throwable throwable = rtx.getThrowable();
        rtx.set("error.status_code", HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        rtx.set("error.exception", throwable.getCause());
        return null;
    }
}
